/*
* @Author: Administrator
* @Date:   2018-01-27 15:15:13
* @Last Modified by:   Administrator
* @Last Modified time: 2018-01-27 15:32:01
*/
const express = require('express')
const serverRender = require('./server_render.js')
const path = require('path');
const fs = require('fs');
const serverEntry = require('../../dist/server/server.js')

const serverDist = (app) => {
  app.use('/dist',express.static(path.join(__dirname,'../../dist')))
  app.get('*', function(req,res,next){
    const bundleModule = serverEntry;
    const template = fs.readFileSync(path.join(__dirname,'../../dist/server_template.ejs'),'utf-8')
    serverRender(bundleModule, template, req, res).catch(next)
  })
}

module.exports  = serverDist
